package P124_Async_Callable;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

/**
 * 异步运算 Callable接口
 * @author xufy
 * @version 1.0
 **/
public class AsyncCallable {

    public static void main(String[] args) throws InterruptedException, ExecutionException {
        ExecutorService es=Executors.newSingleThreadExecutor();
        Future<Integer> future=es.submit(new TaxCalcuator(100));
        while(!future.isDone()){
            TimeUnit.MILLISECONDS.sleep(200);
            //输出进度符号
            System.out.print("#");
        }
        System.out.println("\n 计算完成，税金是："+future.get()+"");
        es.shutdown();
    }

}
class TaxCalcuator implements Callable<Integer>{
    private int seedMoney;
    public TaxCalcuator(int _seedMoney){
        seedMoney=_seedMoney;
    }
    @Override
    public Integer call() throws Exception {
        //10s
        TimeUnit.MILLISECONDS.sleep(10000);
        return seedMoney/10;
    }
}